<template>
  <layout :config="navConfig">
    <template #default>
      <div class="m-review-tab">
        <label style="width: 100%">
          <input type="radio" style="width: 100%" v-model="activeTab" :value="1">
          <span style="width: 100%">修改密码</span>
        </label>
      </div>

      <div class="m-review-form" v-show="activeTab===1">
        <div class="form-col">
          <div class="col-text">新密码</div>
          <input type="text" v-model="formData.newpass">
        </div>
        <div class="form-col">
          <div class="col-text">原始密码</div>
          <input type="password" v-model="formData.old">
        </div>

      </div>

      <button class="m-review-button" @click="confirm">确认</button>
    </template>
  </layout>
</template>

<script lang="ts">
    import {Component, Vue} from "vue-property-decorator";
    import {INavigation} from "@/types";
    import qrCode from "vue-qr";
    import {Toast} from "mand-mobile";
    @Component({
        name: "Review",
        components: {
            qrCode
        },
        created: function () {
            Toast.loading("请求中...");
            let usera = JSON.parse(localStorage.getItem('users1'));

            this.$api.getUser({username:usera.username}).then(res => {
                Toast.hide();
                if (res.success == 200) {
                    this.formData.oldpass = res.data.pass;
                    this.formData.id = res.data.id;
                    console.log(res.data);
                }
            }).catch(res => {
                Toast.hide();
            })


        },
    })
    export default class extends Vue {
        navConfig: INavigation = {
            text: "安全设置"
        };
        type= 1;
        paymoney= 0;
        activeTab = 1;
        formData = {
            id:"",
            newpass: "",
            pass: "",
            old:"",
            oldpass: "",
        };

        confirm() {

            this.formData.pass= this.formData.newpass;
            if( this.formData.newpass==""){
                Toast.info("请输入新密码！",500);
                return;
            }
            if( this.formData.old==""){
                Toast.info("请输入原始密码！",500);
                return;
            }
            if( this.formData.old!=this.formData.oldpass){
                Toast.info("原始密码错误！",500);
                return;
            }
            Toast.loading("请求中...");
            this.$api.updateUser(this.formData).then(res => {
                Toast.hide();
                if (res.success == 200) {
                    Toast.info("设置成功",500);
                    console.log(res.data);
                }else{
                    Toast.info("设置失败",500);
                }
            }).catch(res => {
                Toast.hide();
                Toast.info("设置失败",500);
            })
        }
    }
</script>

<style lang="scss">
  @import "../assets/styles/review.scss";
</style>

